#!/usr/bin/python

import unittest

from google.appengine.api import memcache
from google.appengine.datastore import datastore_stub_util
from google.appengine.ext import ndb
from google.appengine.ext import testbed


class TestCase(unittest.TestCase):

  def setUp(self):
    super(TestCase, self).setUp()

    self.testbed = testbed.Testbed()
    self.testbed.setup_env(app_id='test-app')
    # Then activate the testbed, which prepares the service stubs for use.
    self.testbed.activate()

    self.testbed.init_memcache_stub()

    self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=1.0)
    self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)

    ndb.utils.DEBUG = False
    self.ctx = ndb.tasklets.make_default_context()
    ndb.tasklets.set_context(self.ctx)

  def tearDown(self):
    memcache.flush_all()
    self.testbed.deactivate()
    super(TestCase, self).tearDown()
